(function() {
	var  img = document.getElementsByClassName('lunbo-img')[0].querySelectorAll('li');
var  list = document.getElementsByClassName('list')[0].querySelectorAll('li');
var lunbo = document.getElementsByClassName('lunbo')[0];
var you = document.getElementsByClassName('you')[0];
var zuo = document.getElementsByClassName('zuo')[0];

//console.log(lunbo);
//console.log(you);
//console.log(zuo);
//var index = 0;//设置下标
//function move() {
//	lunbo[index].style.display = 'none';//隐藏上一张图片，循环至下一张
//	index++;
////	console.log(lunbo[index]);
//	if(index === 6){
//		index = 0;
//	}
//	lunbo[index].style.display = 'block';	
//}
//setInterval(move, 3000);


//每隔多长时间换张照片
var time = 4000;
//定时器
var timer;
//显示当前的图片的下标
var cur = 0;
//给每隔圆点添加移入事件
for(var i = 0, len = list.length;i < len;i++) {
	list[i].index = i;   //list的li的下标等于i
	list[i].onclick = function() {
		cur = this.index;
		cur--;    //点击时与li相对应
		move();
	};
}
// 自动走，启动定时器
timer = setInterval(move,time);
// 鼠标点击时清除定时器
list.onclick = function() {
    clearInterval(timer);
};
// 鼠标时启动定时器
list.onclick = function() {
    timer = setInterval(move, time);
};
// 轮播切换函数
function move() {
    var len = img.length;
    // 下一帧
    cur++;
    if(cur === len) {
        cur = 0;
    }
    
    // 隐藏所有图片
    for(var i = 0; i < len; i++) {
        img[i].style.display = 'none';
        list[i].style.background = 'rgba(0,0,0,.4)';
    }
    // 显示当前这一图片
    img[cur].style.display = 'block';
    list[cur].style.background = '#fff';
}
lunbo.onmouseover = function() {
    clearInterval(timer);
};
lunbo.onmouseout = function(){
    timer = setInterval(move, time);
};

//两边箭头设置点击切换
you.onclick=function(){
	   // 隐藏所有图片
    for(var i = 0; i < len; i++) {
        img[i].style.display = 'none';
        list[i].style.background = 'rgba(0,0,0,.4)';
    }
    cur++;
    if(cur===6){
    		cur=0;
    }
    img[cur].style.display = 'block';
    list[cur].style.background = 'rgba(255,255,255,1)';
}

$('.zuo').click(function() {
	cur = --cur < 0 ? 5 : cur;
	$('.lunbo-img li').eq(cur).show().siblings().hide();
	$('.list li').eq(cur).css('background', 'rgba(255,255,255,1)').siblings().css('background', 'rgba(0,0,0,.4)');
});

	
})();




